package com.jh.paymentchannel.repository;

import com.jh.paymentchannel.pojo.MiLianRegister;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


@Repository
public interface MiLianRegisterRepository extends JpaRepository<MiLianRegister, String>, JpaSpecificationExecutor<MiLianRegister> {

    @Query("select ml from  MiLianRegister ml where ml.userId=:userId and ml.debitRate=:debitRate and ml.state = '1'")
    public MiLianRegister getMiLianRegisterByUseridAndRate(@Param("userId") long userId, @Param("debitRate") String debitRate);

    @Query("select ml from  MiLianRegister ml where ml.userId=:userId and ml.state = '1'")
    public MiLianRegister getMiLianRegisterByUserid(@Param("userId") long userId);

    @Modifying
    @Query("update MiLianRegister ml set ml.state = '0' where userId=:userId and bankCard=:bankCard")
    public Integer deleteMiLianRegisterByUIdAndBankId(@Param("userId") long userId, @Param("bankCard") String bankCard);

}
